<template>
  <Container  class="brand-list">
    <Tabs v-model="tab">
      <TabPane label="基金限时设置" name="tab1" style="background:white">
        <Form :model="form" :label-width="150" ref="form" :rules="rules">
          <FormItem label="门店APP申请时间(天)" prop="applyDay">
            <Row>
              <Col span="13">
                每月
                <InputNumber :max="31" :min="1" v-model="form.applyDay"></InputNumber> 日前
              </Col>
            </Row>
          </FormItem>
          <FormItem label="业务通评分时间" prop="ratingDay">
            <Row>
              <Col span="13">
                次月
                <InputNumber :max="31" :min="1" v-model="form.ratingDay"></InputNumber> 日前
              </Col>
            </Row>
          </FormItem>
        </Form>
        <div style="margin-left:60px;">
          <Button size="large" class="mr" type="primary" @click="onSave" :disabled="disabled">确定</Button>
        </div>
      </TabPane>
    </Tabs>
  </Container>
</template>
<script>
import { clearEmpty } from '@/util'
export default {
  data() {
    return {
      tab: 'tab1',
      form: {
        status: 'pass',
        id: '',
        applyDay: '',
        ratingDay: ''
      },
      disabled: false,
      rules: {
        applyDay: [{ required: true, message: '门店APP申请时间不能为空', type: 'number', trigger: 'change' }],
        ratingDay: [{ required: true, message: '业务通评时间不能为空', type: 'number', trigger: 'change' }]
      }
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      this.form.status = 'loading'
      this.$ajaxGet('/setting/fund_time_limit/detail').then(data => {
        this.form = {
          id: data.id,
          applyDay: data.applyDay,
          ratingDay: data.ratingDay
        }
        this.form.status = 'pass'
        this.backTableTop()
      })
      .catch(() => {
        this.form.status = 'error'
      })
    },
    onSave() {
      if (this.disabled) return
      this.$refs["form"].validate(valid => {
        if (valid) {
          let text = this.form.id ? '编辑' : '新增'
          let url = '/setting/fund_time_limit/save'
          let param = {
            id: this.form.id,
            applyDay: this.form.applyDay,
            ratingDay: this.form.ratingDay
          }
          param = clearEmpty(param)
          // if (this.form.id) param.id = this.form.id
          this.form.status = 'loading'
          this.$jsonPost(url, param).then(data => {
            this.$Notice.success({
              title: `${text}成功`
            })
            this.form.status = 'pass'
            this.disabled = false
          }).catch(() => {
            this.form.status = 'pass'
            this.disabled = false
          })
        } else {
          this.disabled = false
        }
      })
    }
  }
}
</script>